import axios from 'axios'

// Create axios instance
const api = axios.create({
  baseURL: '/api',
  timeout: 5000
})

// Dish related APIs
export const dishApi = {
  // Get all dishes
  getDishes: () => api.get('/dish/list'),
  
  // Get dish by id
  getDish: (id) => api.get(`/dish/${id}`),
  
  // Add new dish
  addDish: (dish) => api.post('/dish', dish),
  
  // Update dish
  updateDish: (id, dish) => api.put(`/dish/${id}`, dish),
  
  // Delete dish
  deleteDish: (id) => api.delete(`/dish/${id}`)
}

// Order related APIs
export const orderApi = {
  // Create new order
  createOrder: (dishIds, quantities) => api.post('/order', null, {
    params: {
      dishIds: dishIds.join(','),
      quantities: quantities.join(',')
    }
  }),
  
  // Pay order
  payOrder: (id) => api.post(`/order/${id}/pay`),
  
  // Cancel order
  cancelOrder: (id) => api.post(`/order/${id}/cancel`),
  
  // Get order summary
  getOrderSummary: () => api.get('/order/summary'),

  // Get order list with pagination
  getOrderList: (page = 1, size = 10, status) => api.get('/order/list', {
    params: {
      page,
      size,
      status
    }
  }),

  // Get order detail
  getOrderDetail: (id) => api.get(`/order/${id}`)
} 